<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>眼镜店-用户中心</title>
	<link rel="stylesheet" type="text/css" href="css/reset.css">
	<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
	<div class="header_con">
		<div class="header">
			<div class="welcome fl">欢迎来到眼镜店!</div>
			<div class="fr">
				<%
					if( request.getSession().getAttribute("uname") == null ){
				%>
						<div class="login_btn fl">
							<a href="login.html">登录</a>
							<span>|</span>
							<a href="register.html">注册</a>
						</div>
				<%
					}else{
						String uname=request.getSession().getAttribute("uname")+"";
				%>
						<div class="login_info fl" style="display:block">
							欢迎您：<em><%=uname %></em>
						</div>
				<%
					}
				%>
			</div>
		</div>		
	</div>

	<div class="search_bar clearfix">
		<b class="sub_page_name fl">&nbsp;&nbsp;&nbsp;&nbsp;用户中心</b>
		<div class="search_con fr">
			<input type="text" class="input_text fl" name="" placeholder="搜索商品">
			<input type="button" class="input_btn fr" name="" value="搜索">
		</div>		
	</div>

	<div class="main_con clearfix">
		<div class="left_menu_con clearfix">
			<h3>用户中心</h3>
			<ul>
				<li><a href="user_center_info.jsp">· 个人信息</a></li>
				<li><a href="user_center_order.jsp">· 全部订单</a></li>
				<li><a href="user_center_site.jsp" class="active">· 收货地址</a></li>
			</ul>
		</div>
		<div class="right_content clearfix">
				<h3 class="common_title2">收货地址</h3>
				<div class="site_con">
					<dl>
						<dt>当前地址：</dt>
						<dd id="nowaddr"></dd>
					</dl>
					<dl id="allinfo">
												
					</dl>					
				</div>
				<h3 class="common_title2">编辑地址</h3>
				<div class="site_con">
					<form>
						<div class="form_group">
							<label>收件人：</label>
							<input id="uname" type="text" name="">
						</div class="form_group">
						<div>
							<label>省：</label>
							<select id="prov">
								<option>湖南省</option>
							</select>
							<label>市：</label>
							<select id="city">
								<option>衡阳市</option>
							</select>
							<label>区域：</label>
							<select id="area">
								<option>蒸湘区</option>
							</select>
						</div>
						<div class="form_group form_group2">
							<label>详细地址：</label>
							<textarea id="addr" class="site_area"></textarea>
						</div>
						<div class="form_group">
							<label>邮编：</label>
							<input type="text" name="">
						</div>
						<div class="form_group">
							<label>手机：</label>
							<input id="tel" type="text" name="">
						</div>

						<input type="button" onclick="addAddress()" name="" value="提交" class="info_submit">
					</form>
				</div>
		</div>
	</div>



	<div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京眼镜店信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>
	
	<script type="text/javascript" src="js/jquery-2.2.3.min.js"></script>
	<script>
	if( $(".login_btn").html() ){
				//提示用户先登录
				alert("请先登录");
				location.href="index.jsp";
			}
	
	$.post("orderServlet",{
		op:'getAllAddr',
	},function(data){
		//先判断
		if( data.length<=0 ){
			//没有值
			$("#nowaddr").html("请添加收货地址");
		}else{
			var str='<dt>其他地址：</dt>';
			for( var i=0;i<data.length;i++ ){
				if( data[i].status == 1 ){
					//默认地址
					$("#nowaddr").html( data[i].province+" "+data[i].city+" "+data[i].area+" "+data[i].addr +
							 " ("+data[i].name+" 收)" + data[i].tel );
				}else{
					str+='<dd>'+data[i].province+' '+data[i].city+' '+data[i].area+' '+data[i].addr +
						 ' ('+data[i].name+' 收)' + data[i].tel+'<input onclick="setDefault('+data[i].ano+')" type="button" value="设为默认地址" /></dd>';
				}
			}
			$("#allinfo").html( str );
		}
	},"json");
	
	function setDefault(ano){
		$.post("orderServlet",{
			op:'setDefault',
			ano:ano
		},function(data){
			if( data>0 ){
				location.reload();
			}else{
				alert("设置失败");
			}
		},"json");
	}
	
	function addAddress(){
		var uname=$("#uname").val();
		var prov=$("#prov").val();
		var city=$("#city").val();
		var area=$("#area").val();
		var addr=$("#addr").val();
		var tel=$("#tel").val();
		
		$.post("orderServlet",{
			op:'addAddress',
			uname:uname,
			prov:prov,
			city:city,
			area:area,
			addr:addr,
			tel:tel
		},function(data){
			if( data>0 ){
				location.reload();
			}else{
				alert("添加失败");
			}
		},"text");
	}
	
	</script>
</body>
</html>